$(document).ready(function(){
		var jupsoo_id;
		var user_id;
		var pagenum;
		$(".resTr").click(function(){
			//alert("aaa");
			var idx = $(".resTr").index(this);
			jupsoo_id = $("input[name=jid]").eq(idx).val();
			user_id = $("input[name=uid]").eq(idx).val();
			pagenum = $(".pgnum").val();
			//alert(pagenum);
		});
		
		$(".resTr").hover(function(){
			var idx = $(".resTr").index(this);
			$(".resTr").eq(idx).css("background-color", "#AFEEEE");
		}, function(){
			var idx = $(".resTr").index(this);
			$(".resTr").eq(idx).css("background-color", "white");
		});
		
		deletebtn = function(){
			$.ajax({
				url : "cancelres.do",
				data : "jupsoo_id=" + jupsoo_id,
				success : function(data){
					setTimeout(reset(), 10);
				},
				error : function(data){
					alert("취소가 실패했습니다");
				}
			});
		}
	
		reset = function(){
			
			$.ajax({
				url : "reservationok2.do",
				data : "user_id=" + user_id + "&pageNumber=" + pagenum,
				dateType : "json",
				success : function(data){	
					var html;
					var html2="";
					$('.resTr').remove();
					$(".pgul").empty();
					for(var i = 0; i < data.reslist.length; i++){
						html += "<tr class='resTr'><td class='dept'>"+data.reslist[i].dept_name+"</td>";
						html += "<td class='doctor'>"+data.reslist[i].doctor_name+"</td>";
						html += "<td class='date'>"+data.reslist[i].jupsoo_date+"</td>";
						html += "<td class='time'>"+data.reslist[i].jupsoo_time;
						html += "<input type='hidden' name='uid' class='uid' value='"+data.reslist[i].user_id+"'>";
						html += "<input type='hidden' name='jid' class='jid' value='"+data.reslist[i].jupsoo_id+"'></td></tr>";
					}  				
					if(data.startPage > 1){
						html2 += '<span>';
						html2 += '<a href="reservationok.do?pageNumber='+(data.startPage-1)+'&user_id='+user_id+'">이전</a>';
						html2 += '</span>';
					}
					for(var i = data.startPage; i <= data.endPage; i++){
						if(data.pageNumber == i){
							html2 += '<span>';
							html2 += '<a href="reservationok.do?pageNumber='+i+'&user_id='+user_id+'" style="text-decoration: blink; color: #483D8B; font-weight: bold;">'+i+'</a>';
							html2 += '</span>';
						}
						else{
							html2 += '<span>';
							html2 += '<input type="hidden" value="'+data.pageNumber+'" class="pgnum" name="pgnum">';
							html2 += '<a href="reservationok.do?pageNumber='+i+'&user_id='+user_id+'" style="text-decoration: none; color: gray;">'+i+'</a>';
							html2 += '</span>';
						}
					}
					if(data.endPage < data.totalPageCount){
						html2 += '<span>'; 
						html2 += '<a href="reservationok.do?pageNumber='+(data.endPage+1)+'&user_id='+user_id+'">다음</a>';
						html2 += '</span>';
					}
					html2 += '</ul>';  
					$('.table_style').append(html);
					$('.pgul').append(html2);
				},
				error : function(data){
					alert("실패");
				} 
			}); 
		} 
	});